home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / imc9103.zip / AFC.C < prev    next >
Text File  |  1991-02-13  |  4KB  |  95 lines

  1. /**************************************************************
  2. * AFC.C - this program calculates the execution time of the   *
  3. *   AFC -- the average function call.                         *
  4. *                                                             *
  5. * To compile: "cl /Od /Fa /Gs afc.c"                          *
  6. * RHS 9/30/90                                                                  *
  7. **************************************************************/
  8. #include<time.h>
  9. #include<process.h>
  10. #include<stdio.h>
  11. #include<stdlib.h>
  12.  
  13. void cdecl main(void);
  14.  
  15. /**************************************************************
  16. * The test functions used to generate an AFC                  *
  17. **************************************************************/
  18. void _cdecl empty1(void)                   {   }
  19. void _cdecl empty11(int x)                 {   }
  20. void _cdecl empty12(int x, int y)          {   }
  21. void _far _cdecl empty1f(void)             {   }
  22. void _far _cdecl empty11f(int x)           {   }
  23. void _far _cdecl empty12f(int x, int y)    {   }
  24.  
  25. void _pascal empty2(void)                  {   }
  26. void _pascal empty21(int x)                {   }
  27. void _pascal empty22(int x, int y)         {   }
  28. void _far _pascal empty2f(void)            {   }
  29. void _far _pascal empty21f(int x)          {   }
  30. void _far _pascal empty22f(int x, int y)   {   }
  31.  
  32. void _fastcall empty3(void)                {   }
  33. void _fastcall empty31(int x)              {   }
  34. void _fastcall empty32(int x, int y)       {   }
  35. void _far _fastcall empty3f(void)          {   }
  36. void _far _fastcall empty31f(int x)        {   }
  37. void _far _fastcall empty32f(int x, int y) {   }
  38.  
  39. #define DEF_ITERATIONS   10000000L
  40.  
  41. /**************************************************************
  42. * TimeFunc - this macro displays the string 's' and then      *
  43. * calculates the calculates and displays the average          *
  44. * execution time for the function call 'f'.                   *
  45. **************************************************************/
  46. #define TimeFunc(s,f)                        \
  47.     printf(s);                                    \
  48.    iterations = setting;               \
  49.     start = clock();                            \
  50.     for ( ; iterations; iterations--)   \
  51.         f;                                            \
  52.     end = clock();                                \
  53.     test = (float)(end-start);                \
  54.    test /= (float)CLK_TCK;             \
  55.     printf("AFC: %04.2f uSec.\n", test*(1E6/setting))
  56.  
  57.  
  58. /**************************************************************
  59. * main - calculates the average function call overhead for    *
  60. * each of the specified functions.                            *
  61. **************************************************************/
  62. void _cdecl main(void)
  63.     {
  64.     long start, end = 0L;
  65.     unsigned long iterations, setting = DEF_ITERATIONS;
  66.     float test = (float)0;
  67.     int x, y;
  68.  
  69.       TimeFunc("void _cdecl empty1(void).....................",empty1());
  70.     TimeFunc("void _cdecl empty11(int x)...................",empty11(x));
  71.     TimeFunc("void _cdecl empty12(int x, int y)............",empty12(x,y));
  72.     TimeFunc("void _far _cdecl empty1f(void)...............",empty1f());
  73.     TimeFunc("void _far _cdecl empty11f(int x).............",empty11f(x));
  74.     TimeFunc("void _far _cdecl _empty12f(int x, int y).....",empty12f(x,y));
  75.  
  76.     printf("\n");
  77.  
  78.     TimeFunc("void _pascal empty2(void)....................",empty2());
  79.     TimeFunc("void _pascal empty21(int x)..................",empty21(x));
  80.     TimeFunc("void _pascal empty22(int x, int y)...........",empty22(x,y));
  81.     TimeFunc("void _far _pascal empty2f(void)..............",empty2f());
  82.     TimeFunc("void _far _pascal empty21f(int x)............",empty21f(x));
  83.     TimeFunc("void _far _pascal empty22f(int x, int y).....",empty22f(x,y));
  84.  
  85.     printf("\n");
  86.  
  87.     TimeFunc("void _fastcall empty3(void)..................",empty3());
  88.     TimeFunc("void _fastcall empty31(int x)................",empty31(x));
  89.     TimeFunc("void _fastcall _empty32(int x, int y)........",empty32(x,y));
  90.     TimeFunc("void _far _fastcall empty3f(void)............",empty3f());
  91.     TimeFunc("void _far _fastcall empty31f(int x)..........",empty31f(x));
  92.     TimeFunc("void _far _fastcall empty32f(int x, int y)...",empty32f(x,y));
  93.  
  94.     }
  95.